package com.cloudbroker.bcs.csvc.sms.service.facade;

import java.util.Map;

import com.cloudbroker.bcs.csvc.sms.api.constants.SMSFields;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.cloudbroker.bcs.csvc.base.facade.service.HSBCCSServiceFacade;
import com.cloudbroker.bcs.csvc.sms.api.constants.SMSImplTypes;
import com.cloudbroker.bcs.csvc.sms.api.service.SMSService;
import com.cloudbroker.bcs.csvc.sms.common.service.SMSImplService;

@Service
public class SMSServiceFacade extends HSBCCSServiceFacade<SMSImplService> implements SMSService {
    
    private static final Logger LOGGER = LoggerFactory.getLogger(SMSServiceFacade.class);
    
    private static OperationHandler<SMSImplService> SEND_SINGLE_HANDLER = new OperationHandler<SMSImplService>() {
        @Override
        public void callImpl(SMSImplService implService, Map<String, Object> param, Map<String, Object> result) {
            implService.sendSingle(param, result);
        }
    };
    
    private static OperationHandler<SMSImplService> SEND_BATCH_HANDLER = new OperationHandler<SMSImplService>() {
        @Override
        public void callImpl(SMSImplService implService, Map<String, Object> param, Map<String, Object> result) {
            implService.sendBatch(param, result);
        }
    };

    private static OperationHandler<SMSImplService> SEND_MAIL_HANDLER = new OperationHandler<SMSImplService>() {
        @Override
        public void callImpl(SMSImplService implService, Map<String, Object> param, Map<String, Object> result) {
            implService.sendMail(param, result);
        }
    };
    
    @Override
    public Map<String, Object> sendSingle(Map<String, Object> param) {
        return operate(SEND_SINGLE_HANDLER, param , SMSFields.SMS_IMPL);
    }
    
    @Override
    public Map<String, Object> sendBatch(Map<String, Object> param) {
        return operate(SEND_BATCH_HANDLER, param , SMSFields.SMS_IMPL);
    }

    @Override
    public Map<String, Object> sendMail(Map<String, Object> param) {
        return operate(SEND_MAIL_HANDLER , param , SMSFields.MAIL_IMPL);
    }

    @Override
    protected Logger getLogger() {
        return LOGGER;
    }
    
    @Override
    protected String getDefaultImplType() {
        return SMSImplTypes.MOCK;
    }
    
}
